<template>
	<view class="content_box">
		<view class="header">
			<view>VIP会员</view>
		</view>
		<!-- tab切换 -->
		<view class="head_tab">
			<scroll-view class="scroll-view_H" scroll-x scroll-left="0">
				<view id="demo1" class="scroll-view-item_H" :class="{active:item == currentTab}"
					@click="changeTab(item)" v-for="(item,index) in tab" :key="index">{{item}}</view>
			</scroll-view>
		</view>

		<view class="content_box2">
			<!-- 卡片 -->
			<view class="card" style="background: url('/static/image/juxing98.png') no-repeat">
				<image class="headPic" :src="avatarUrl"></image>
				<view class="info">
					<text class="welcome">欢迎你，{{nickName}}</text>
					<view class="liar">8元开通VIP,畅学明初独家菜谱</view>
				</view>
				<button class="btn" @click="toOpenVipPage">开通</button>
				<view class="three">
					<view class="item">
						<image src="/static/image/mengbanzu254.png"></image>
						<text>名厨课程</text>
					</view>
					<view class="item">
						<image src="/static/image/mengbanzu255.png"></image>
						<text>无广告打扰</text>
					</view>
					<view class="item">
						<image src="/static/image/mengbanzu256.png"></image>
						<text>身份标识</text>
					</view>
				</view>
			</view>
			<!-- vip最新推荐 -->
			<view class="newVip">
				<text class="newTitle">VIP最新推荐</text>
				<scroll-view class="scroll-view_H" scroll-x scroll-left="0">
					<view class="scroll-view-item_H" v-for="item in commendData" :key="item._id">
						<image class="newVip_pic" :src="item.coverpic"></image>
						<view class="name">{{item.name}}</view>
						<view class="buttom">
							<text class="left">{{item.pageview}}</text>
							<text class="right">{{item.collections}}</text>
						</view>
					</view>
				</scroll-view>
			</view>
			<!-- 显示免费体验 -->
			<view class="newVip">
				<text class="newTitle">限时免费体验</text>
				<scroll-view class="scroll-view_H" scroll-x scroll-left="0">
					<view class="scroll-view-item_H" v-for="item in freeData" :key="item._id">
						<image class="newVip_pic" :src="item.coverpic"></image>
						<view class="name">{{item.name}}</view>
						<view class="buttom">
							<text class="left">{{item.pageview}}</text>
							<text class="right">{{item.collections}}</text>
						</view>
					</view>
				</scroll-view>
			</view>
			<!-- 猜你喜欢 -->
			<view class="newVip">
				<text class="newTitle">猜你喜欢</text>
				<scroll-view class="scroll-view_H" scroll-x scroll-left="0">
					<view class="scroll-view-item_H" v-for="item in likes" :key="item._id">
						<image class="newVip_pic" :src="item.coverpic"></image>
						<view class="name">{{item.name}}</view>
						<view class="buttom">
							<text class="left">{{item.pageview}}</text>
							<text class="right">{{item.collections}}</text>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getVipCommendApi,
		getfreeApi,
		getLikesApi,
		/* getVipExclusiveApi */
	} from "../../apis/vip.js"
	export default {
		mounted() {
			//vip推荐
			this.getVipCommendData()
			//限时免费
			this.getFreeData()
			//猜你喜欢
			this.getLikesData()
			//精品名厨(会员专享)
			// this.getVipExclusiveData()
			const userInfo = uni.getStorageSync("userInfo")
			if (userInfo._id) {
				this.avatarUrl = userInfo.avatarUrl
				this.nickName = userInfo.nickName
			}
		},
		data() {
			return {
				tab: ["推荐", "免费体验", "小白入门", "快手菜", "家常菜", "面食", "川湘菜", "凉菜"],
				currentTab: "推荐",
				commendData: [],
				freeData:[],
				likes:[],
				avatarUrl: "/static/image/zu428.png",
				nickName: "立即登录"
				/* exclusiveData:[] */
			};
		},
		methods: {
			//tab切换
			changeTab(val) {
				this.currentTab = val
			},
			//获取vip推荐
			getVipCommendData() {
				getVipCommendApi().then(res => {
					this.commendData = res.menus
				})
			},
			//获取限时免费体验
			getFreeData(){
				getfreeApi().then(res => {
					this.freeData = res.menus
				})
			},
			//获取猜你喜欢
			getLikesData(){
				getLikesApi().then(res => {
					this.likes = res.menus
				})
			},
			////精品名厨(会员专享)
			/* getVipExclusiveData(){
				getVipExclusiveApi().then(res => {
					this.exclusiveData = res.menus
				})
			}, */
			//跳转到开会员页面
			toOpenVipPage(){
				uni.navigateTo({
					url:"/pages/sub/myVip/myVip"
				})
			}
			
		}
	}
</script>

<style lang="scss" scoped>
	//头部
	.header {
		width: 100%;
		height: 160rpx;
		background-color: #ee7b2d;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 1;

		view {
			padding-top: 30rpx;
			line-height: 160rpx;
			text-align: center;
			color: #ffffff;
			font-size: 36rpx;
		}
	}

	.content_box {
		padding: 159rpx 0rpx 0rpx;

		.head_tab {

			//tab切换
			.scroll-view_H {
				white-space: nowrap;
				width: 100%;
				height: 100rpx;
				background-color: #ee7b2d;

				.scroll-view-item_H {
					display: inline-block;
					height: 100rpx;
					padding: 0 32rpx;
					line-height: 100rpx;
					font-size: 24rpx;
					color: #ffffff;
				}

				.active {
					font-size: 40rpx;
					color: white;
					font-weight: bold;
				}
			}
		}


	}

	//内容
	.content_box2 {
		width: 100%;
		box-sizing: border-box;
		padding: 14rpx 32rpx 0rpx;

		//卡片
		.card {
			width: 100%;
			height: 324rpx;
			position: relative;

			.info {
				width: 400rpx;
				position: absolute;
				top: 44rpx;
				left: 180rpx;

				.welcome {
					font-size: 24rpx;
					color: #939393;

				}

				.liar {
					margin-top: 18rpx;
					font-size: 28rpx;
					color: #e6e6e6;
					font-weight: bold;
				}
			}

			.headPic {
				width: 128rpx;
				height: 128rpx;
				position: absolute;
				top: 32rpx;
				left: 32rpx;
				border-radius: 50%;
			}

			.btn {
				width: 108rpx;
				height: 34rpx;
				background-color: #e5b293;
				border-radius: 17rpx;
				font-size: 22rpx;
				line-height: 34rpx;
				color: #76401f;
				position: absolute;
				top: 52rpx;
				right: 32rpx;
			}

			.three {
				width: 100%;
				height: 96rpx;
				padding: 0rpx 32rpx;
				box-sizing: border-box;
				background-image: linear-gradient(0deg, #545454 0%, #000000 100%);
				border-radius: 16rpx;
				position: absolute;
				left: 0;
				bottom: 0;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.item {
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;

					image {
						width: 40rpx;
						height: 40rpx;
					}

					text {
						margin-top: 10rpx;
						font-size: 22rpx;
						color: #f9d9b3;

					}
				}
			}
		}

		//vip最新推荐
		.newVip {
			height: 380rpx;
			margin-top: 40rpx;

			.newTitle {
				font-size: 40rpx;
				color: #161616;
				font-weight: 550;
			}

			.scroll-view_H {
				white-space: nowrap;
				width: 100%;
				height: 300rpx;
				margin-top: 24rpx;

				.scroll-view-item_H {
					display: inline-block;
					width: 314rpx;
					height: 100%;
					margin-right: 12rpx;

					.newVip_pic {
						width: 100%;
						height: 220rpx;
						border-radius: 8rpx;
					}

					.name {
						font-size: 26rpx;
						color: #575757;
						margin-top: 8rpx;
					}

					.buttom {
						font-size: 18rpx;
						margin-top: 6rpx;
						color: #aaaaaa;

						.left {
							padding-right: 36rpx;
							background: url("../../static/image/mengbanzu278.png") no-repeat;
							background-position: right;
							margin-right: 60rpx;
						}

						.right {
							padding-right: 36rpx;
							background: url("/static/image/mengbanzu279.png") no-repeat;
							background-position: right;
						}
					}
				}
			}
		}
	}
	
</style>
